import hashlib
def get_md5(final_path):
    try:
        with open(final_path, 'r') as file_h:
            return hashlib.md5(file_h.read()).hexdigest()
    except IOError:
        return
        
        
def recursive_dict_update(d, u):
    for k, v in u.iteritems():
        if isinstance(v, dict):
            r = recursive_dict_update(d.get(k, {}), v)
            d[k] = r
        elif isinstance(v, (basestring, int)):
            d[k] = v
        elif isinstance(v, list):
            if k in d and not isinstance(d[k], list):
                raise Exception('Cant merge list with %s' % v.__class__.__name__)

            # simple merge case, merge two lists of hashable types (int, str)
            if k in d:
                d[k] = d[k] + v
            else:
                d[k] = v
        else:
            raise Exception('Unknown pair to merge %s' % v.__class__.__name__)
        #    print 'Set %s to %s ' % (k , v)
    return d
